home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / File class library / sources / CCustomIcon.c next >
Text File  |  1992-10-08  |  3KB  |  128 lines

  1. /*
  2.  
  3.   CCustomIcon.c
  4.   Superclass:    CIsleResFile
  5.  
  6.      Facility to associate custom icons with files and folders
  7.  
  8.   October 8, 1992  isl
  9.   
  10. */
  11.  
  12. #include    <CCustomIcon.h>
  13.  
  14. extern    OSType    gSignature;
  15.  
  16. /*=====================*/
  17. /*===---------------===*/
  18.  
  19. void CCustomIcon::ICustomIcon(void)
  20. Begin
  21.     itsIconSuite= Null;
  22.  
  23.     CIsleResFile::IResFile();
  24. End
  25.  
  26. /*===---------------===*/
  27.  
  28. void    CCustomIcon::FetchIconFamily (short iconID)
  29. Begin
  30.     Boolean    state;                                    //    Lockedness of this object
  31.  
  32.     MoveHHi((Handle)this);
  33.     state= Lock(True);                            //    We need a solid address below
  34.  
  35.     FailOSErr( GetIconSuite(&itsIconSuite, iconID, (svAllLargeData+svAllSmallData)) );
  36.     
  37.     Lock(state);                                        //    Restore lockedness
  38. End
  39.  
  40. /*===---------------===*/
  41.  
  42. void    CCustomIcon::PlaceIconFamily (void)
  43. Begin
  44.     Handle    anIcon= Null;                        //    One icon of the suite
  45.  
  46.     if (IsOpen())
  47.         Close();
  48.         
  49.     Open(fsWrPerm);                                    //    Open the file and request write permission, only
  50.                         
  51.     TRY
  52.     {
  53.         FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Large1BitMask) );
  54.         DetachResource(anIcon);                //    Make a duplicate
  55.         FailResError();
  56.         AddResource(anIcon, Large1BitMask, kCustomIconResource, kIconInfo);
  57.         FailResError();
  58.         ForgetResource(anIcon);                //    Leave it be and get ready for the next
  59.         
  60.         FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Large4BitData) );
  61.         DetachResource(anIcon);
  62.         FailResError();
  63.         AddResource(anIcon, Large4BitData, kCustomIconResource, kIconInfo);
  64.         FailResError();
  65.         ForgetResource(anIcon);
  66.         
  67.         FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Large8BitData) );
  68.         DetachResource(anIcon);
  69.         FailResError();
  70.         AddResource(anIcon, Large8BitData, kCustomIconResource, kIconInfo);
  71.         FailResError();
  72.         ForgetResource(anIcon);
  73.         
  74.         FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Small1BitMask) );
  75.         DetachResource(anIcon);
  76.         FailResError();
  77.         AddResource(anIcon, Small1BitMask, kCustomIconResource, kIconInfo);
  78.         FailResError();
  79.         ForgetResource(anIcon);
  80.         
  81.         FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Small4BitData) );
  82.         DetachResource(anIcon);
  83.         FailResError();
  84.         AddResource(anIcon, Small4BitData, kCustomIconResource, kIconInfo);
  85.         FailResError();
  86.         ForgetResource(anIcon);
  87.         
  88.         FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Small8BitData) );
  89.         DetachResource(anIcon);
  90.         FailResError();
  91.         AddResource(anIcon, Small8BitData, kCustomIconResource, kIconInfo);
  92.         FailResError();
  93.         ForgetResource(anIcon);
  94.     }
  95.     CATCH
  96.     {
  97.         ForgetResource(anIcon);
  98.     }
  99.     ENDTRY
  100.     
  101.     Update();                                                    //    Reflect the changes
  102.     Close();
  103. End
  104.  
  105. /*===---------------===*/
  106.  
  107. void CCustomIcon::ActivateCustomIcon(void)
  108. Begin
  109.     CInfoPBRec    specs;                                //    The icon file's specs
  110.                 
  111.     GetMacCatInfo(&specs);                        //    Get our file's
  112.     specs.hFileInfo.ioFlFndrInfo.fdFlags &= kInitedOff;
  113.     specs.hFileInfo.ioFlFndrInfo.fdFlags |= kCustomIcon;
  114.     SetMacCatInfo(&specs);                        //    For instant effect, make sure the parent folder's modification date is set to now
  115. End
  116.  
  117. /*===---------------===*/
  118.  
  119. void CCustomIcon::Dispose(void)
  120. Begin
  121.     if (itsIconSuite)
  122.         FailOSErr(DisposeIconSuite(itsIconSuite, True));
  123.     
  124.     inherited::Dispose();
  125. End
  126.  
  127. /*===---------------===*/
  128. /*=====================*/